package com.aurora.app.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.aurora.app.enums.ChatMessageType;
import com.aurora.base.entity.BaseEntity;

/**
 * 聊天记录
 * （保留七天）
 * @author yongjiang.lin
 *
 */
@Entity
@Table(name="tb_chat")
public class Chat extends BaseEntity {
	private User user;
	private User toUser;
	private String message;
	
	//默认文本
	private ChatMessageType chatMessageType = ChatMessageType.TEXT;
	private ChatGroup chatGroup;
	
	
	@ManyToOne(cascade = {CascadeType.REFRESH}, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(name = "f_user_id")
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	@ManyToOne(cascade = {CascadeType.REFRESH}, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(name = "f_to_user_id")
	public User getToUser() {
		return toUser;
	}
	public void setToUser(User toUser) {
		this.toUser = toUser;
	}
	@Column(name = "f_message")
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "chat_message_type")
	public ChatMessageType getChatMessageType() {
		return chatMessageType;
	}
	public void setChatMessageType(ChatMessageType chatMessageType) {
		this.chatMessageType = chatMessageType;
	}
	
	@ManyToOne(cascade = {CascadeType.REFRESH}, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(name = "f_chat_group_id")
	public ChatGroup getChatGroup() {
		return chatGroup;
	}
	public void setChatGroup(ChatGroup chatGroup) {
		this.chatGroup = chatGroup;
	}
	
	@Override
	public String toString() {
		return "Chat [user=" + user.getNickName() + ", toUser=" + toUser.getNickName() + ", message=" + message + ", chatMessageType="
				+ chatMessageType.getValue() + ", chatGroup=" + chatGroup.getId() +  "]";
	}
}
